import React from "react";
import PropTypes from "prop-types";

/**
 *  Badge Component
 */
export default class Badge extends React.Component
{
    /**
     * 组件类名
     */
    className = "badge";

    /**
     * 默认属性
     */
    static defaultProps =
    {
        type : "dot",
        style : {},
        children : ""
    };

    /**
     * 属性类型
     */
    static propTypes =
    {
        type : PropTypes.oneOf(["dot", "square"]).isRequired,
        style : PropTypes.object,
        children: PropTypes.any
    };

    componentWillMount()
    {
        if ("dot" === this.props.type) {
            this.className += " badge-dot";
        } else {
            this.className += " badge-square";
        }
    }

    render()
    {
        return <span className={this.className} style={this.props.style}>
            {this.props.children}
        </span>;
    }
}